<template>
  <el-card>
      <el-tabs v-model="activeName"  @tab-click="handleClick" >
          <el-tab-pane label="设备详情" name="basic">
          <el-form ref="form2" :model="form2" :rules="rules2" label-width="20%">
            <h4>设备简要信息</h4>
            <el-row>
              <el-col :span="8">
                <el-form-item label="设备所属车间" prop="equipmentWorkshop">
                  <el-input v-model="form2.equipmentWorkshop" placeholder="请输入设备所属车间" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="设备照片">
                  <imageUpload  v-model="form2.equipmentImg" :limit="2"  :is-show-tip="false"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="设备简介" prop="equipmentRenark">
                  <el-input v-model="form2.equipmentRenark" type="textarea" placeholder="请输入内容" />
                </el-form-item>
              </el-col>
            </el-row>

            <h4>设备主要技术参数</h4>
            <el-row>
              <el-col :span="8">
                <el-form-item label="设备位号" prop="equipmentNo">
                  <el-input v-model="form2.equipmentNo" placeholder="请输入设备位号" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="出厂日期" prop="productionDate">
                  <el-date-picker clearable size="small"
                    v-model="form2.productionDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择出厂日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="数量" prop="num">
                  <el-input v-model="form2.num" placeholder="请输入数量" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span="8">
                <el-form-item label="设备名称" prop="equipmentName">
                  <el-input v-model="form2.equipmentName" placeholder="请输入设备名称" />
                </el-form-item>
              </el-col>
<!--              <el-col :span="8">
                <el-form-item label="安装单位" prop="installationUnit">
                  <el-input v-model="form2.installationUnit" placeholder="请输入安装单位" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="出厂编号" prop="productionNo">
                  <el-input v-model="form2.productionNo" placeholder="请输入出厂编号" />
                </el-form-item>
              </el-col>
            </el-row>


            <el-row>
              <el-col :span="8">
                <el-form-item label="型号" prop="model">
                  <el-input v-model="form2.model" placeholder="请输入型号" />
                </el-form-item>
              </el-col>-->
              <el-col :span="8">
                <el-form-item label="外形尺寸" prop="overallDimension">
                  <el-input v-model="form2.overallDimension" placeholder="请输入外形尺寸" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="总重(kg)" prop="totalWeight">
                  <el-input v-model="form2.totalWeight" placeholder="请输入总重(kg)" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span="8">
                <el-form-item label="最大起吊重量(kg)" prop="liftingWeightMax">
                  <el-input v-model="form2.liftingWeightMax" placeholder="请输入最大起吊重量(kg)" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="制造厂" prop="manufacturer">
                  <el-input v-model="form2.manufacturer" placeholder="请输入制造厂" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="投产日期" prop="productionTime">
                  <el-date-picker clearable size="small"
                    v-model="form2.productionTime"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择投产日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>

            <h4>操作条件及性能</h4>
            <el-row>
              <el-col :span="8">
                <el-form-item label="介质" prop="medium">
                  <el-input v-model="form2.medium" placeholder="请输入介质" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="设计流量(m3/h)" prop="designFlow">
                  <el-input v-model="form2.designFlow" placeholder="请输入设计流量(m3/h)" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="设备转速" prop="speed">
                  <el-input v-model="form2.speed" placeholder="请输入设备转速" />
                </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span="8">
                <el-form-item label="入口温度(℃)" prop="inletTemperature">
                  <el-input v-model="form2.inletTemperature" placeholder="请输入入口温度(℃)" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="正常流量" prop="normalFlow">
                  <el-input v-model="form2.normalFlow" placeholder="请输入正常流量" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="轴功率" prop="shaftPower">
                  <el-input v-model="form2.shaftPower" placeholder="请输入轴功率" />
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="粘度" prop="viscosity">
              <el-input v-model="form2.viscosity" placeholder="请输入粘度" />
            </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="入口压力(MPa)" prop="inletPressure">
              <el-input v-model="form2.inletPressure" placeholder="请输入入口压力(MPa)" />
            </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="气蚀余量(m)" prop="cavitationAllowance">
              <el-input v-model="form2.cavitationAllowance" placeholder="请输入气蚀余量(m)" />
            </el-form-item>
              </el-col>
            </el-row>

            <el-row>

              <el-col :span="8">
                <el-form-item label="扬程(m)" prop="lift">
              <el-input v-model="form2.lift" placeholder="请输入扬程(m)" />
            </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="出口压力(MPa)" prop="outletPressure">
              <el-input v-model="form2.outletPressure" placeholder="请输入出口压力(MPa)" />
            </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="吸入温度下密度" prop="suctionTemperature">
              <el-input v-model="form2.suctionTemperature" placeholder="请输入吸入温度下密度" />
            </el-form-item>
              </el-col>
            </el-row>

            <h4>驱动装置数据</h4>

            <el-row>
              <el-col :span="8">
                <el-form-item label="驱动机" prop="driving">
              <el-input v-model="form2.driving" placeholder="请输入驱动机" />
            </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="驱动转速" prop="drivingSpeed">
              <el-input v-model="form2.drivingSpeed" placeholder="请输入驱动转速" />
            </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="防爆等级" prop="explosionProofGrade">
              <el-input v-model="form2.explosionProofGrade" placeholder="请输入防爆等级" />
            </el-form-item>
              </el-col>
            </el-row>

            <el-row>
              <el-col :span="8">
                <el-form-item label="驱动机型号" prop="drivingMachine">
                  <el-input v-model="form2.drivingMachine" placeholder="请输入驱动机型号" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="驱动机出厂日期" prop="drivingProductionDate">
                  <el-date-picker clearable size="small"
                    v-model="form2.drivingProductionDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择驱动机出厂日期">
                  </el-date-picker>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="驱动机制造厂" prop="drivingManufacturer">
                  <el-input v-model="form2.drivingManufacturer" placeholder="请输入驱动机制造厂" />
                </el-form-item>
              </el-col>
            </el-row>

            <h4>设备正常运行参数</h4>
            <el-form-item label="" prop="equipmentOperationParameters">
              <el-input v-model="form2.equipmentOperationParameters" type="textarea" placeholder="请输入内容" />
            </el-form-item>
            <h4>设备维修维护内容及周期</h4>
            <el-row>
              <el-col :span="8">
                <el-form-item label="中修检修周期" prop="intermediateMaintenanceCycle">
                  <el-input v-model="form2.intermediateMaintenanceCycle" placeholder="请输入中修检修周期" />
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="大修检修周期" prop="overhaulCycle">
                  <el-input v-model="form2.overhaulCycle" placeholder="请输入大修检修周期" />
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="维护信息" name="record">
          <div class="app-container">
              <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
                <el-form-item label="维修时间" prop="repairDate">
                    <el-date-picker clearable size="small"
                    v-model="queryParams.repairDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="选择维修时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="维修人员姓名" prop="repairPoepleName">
                    <el-input
                    v-model="queryParams.repairPoepleName"
                    placeholder="请输入维修人员姓名"
                    clearable
                    size="small"
                    @keyup.enter.native="handleQuery"
                    />
                </el-form-item>

                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-form>

                <el-row :gutter="10" class="mb8">
                    <el-col :span="1.5">
                        <el-button
                        type="primary"
                        plain
                        icon="el-icon-plus"
                        size="mini"
                        @click="handleAdd"
                        v-hasPermi="['system:nmEquipemntRecord:add']"
                        >新增</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button
                        type="success"
                        plain
                        icon="el-icon-edit"
                        size="mini"
                        :disabled="single"
                        @click="handleUpdate"
                        v-hasPermi="['system:nmEquipemntRecord:edit']"
                        >修改</el-button>
                    </el-col>
                    <el-col :span="1.5">
                        <el-button
                        type="danger"
                        plain
                        icon="el-icon-delete"
                        size="mini"
                        :disabled="multiple"
                        @click="handleDelete"
                        v-hasPermi="['system:nmEquipemntRecord:remove']"
                        >删除</el-button>
                    </el-col>
                </el-row>

            <el-table v-loading="loading" :data="nmEquipemntRecordList" @selection-change="handleSelectionChange">
                <el-table-column type="selection" width="55" align="center" />
                <el-table-column label="维修人员姓名" align="center" prop="repairPoepleName" />
                <el-table-column label="维修时间" align="center" prop="repairDate" width="180">
                    <template slot-scope="scope">
                      <span>{{ parseTime(scope.row.repairDate, '{y}-{m}-{d}') }}</span>
                    </template>
                </el-table-column>
                <el-table-column label="故障现象" align="center" prop="faultPhenomenon" />
                <el-table-column label="故障原因分析" align="center" prop="failureCauseAnalysis" />
                <el-table-column label="维修过程记录" align="center" prop="maintenanceProcessRecord" />
                <el-table-column label="创建人姓名" align="center" prop="createName" />
                <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                    <template slot-scope="scope">
                      <el-button
                          size="mini"
                          type="text"
                          icon="el-icon-edit"
                          @click="handleUpdate(scope.row)"
                          v-hasPermi="['system:nmEquipemntRecord:edit']"
                      >修改</el-button>
                      <el-button
                          size="mini"
                          type="text"
                          icon="el-icon-delete"
                          @click="handleDelete(scope.row)"
                          v-hasPermi="['system:nmEquipemntRecord:remove']"
                      >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <pagination
                v-show="total>0"
                :total="total"
                :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize"
                @pagination="getList">
            </pagination>

                <!-- 添加或修改设备维护信息对话框 -->
            <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
                <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                    <!--<el-form-item label="nm_equipment主键" prop="equipId">
                        <el-input v-model="form.equipId" placeholder="请输入nm_equipment主键" />
                    </el-form-item>-->
                    <el-form-item label="维修时间" prop="repairDate">
                    <el-date-picker clearable size="small"
                        v-model="form.repairDate"
                        type="date"
                        value-format="yyyy-MM-dd"
                        placeholder="选择维修时间">
                    </el-date-picker>
                    </el-form-item>
                    <el-form-item label="维修人员姓名" prop="repairPoepleName">
                    <el-input v-model="form.repairPoepleName" placeholder="请输入维修人员姓名" />
                    </el-form-item>

                    <el-form-item label="故障现象" prop="faultPhenomenon">
                    <el-input v-model="form.faultPhenomenon" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="故障原因分析" prop="failureCauseAnalysis">
                    <el-input v-model="form.failureCauseAnalysis" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                    <el-form-item label="维修过程记录" prop="maintenanceProcessRecord">
                    <el-input v-model="form.maintenanceProcessRecord" type="textarea" placeholder="请输入内容" />
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button type="primary" @click="submitForm">确 定</el-button>
                    <el-button @click="cancel">取 消</el-button>
                </div>
            </el-dialog>
          </div>
        </el-tab-pane>
      </el-tabs>
      <el-form label-width="100px">
        <el-form-item style="text-align: center;margin-left:-100px;margin-top:10px;">
          <el-button type="primary" @click="submitEqForm()" v-if="activeName=='basic'">提交</el-button>
          <el-button @click="close()">返回</el-button>
        </el-form-item>
      </el-form>
  </el-card>
</template>

<script>
import { listNmEquipemntRecord, getNmEquipemntRecord, delNmEquipemntRecord, addNmEquipemntRecord, updateNmEquipemntRecord, exportNmEquipemntRecord } from "@/api/jetLinks/nmEquipemntRecord";
import { listNmEquipment, getNmEquipment, delNmEquipment, addNmEquipment, updateNmEquipment, exportNmEquipment,handleQrcode } from "@/api/jetLinks/nmEquipment";
import ImageUpload from '@/components/ImageUpload';

export default {
  name: "NmEquipemntRecord",
  components: {
      ImageUpload
  },
  data() {
    return {
      equip_id:"",
        // 选中选项卡的 name
      activeName: "basic",
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 设备维护信息表格数据
      nmEquipemntRecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        equipId: null,
        repairDate: null,
        repairPoepleName: null,
        repairPoepleId: null,
        faultPhenomenon: null,
        failureCauseAnalysis: null,
        maintenanceProcessRecord: null,
        createName: null,
        createId: null
      },
      // 表单参数
      form: {},
      form2: {},
      // 表单校验
      rules: {
        equipId: [
          { required: true, message: "nm_equipment主键不能为空", trigger: "blur" }
        ],
      },
      rules2: {

      },


    };
  },
  created() {
    const tableId = this.$route.query && this.$route.query.eqpId;
    if (tableId) {
        this.equip_id = tableId;
        this.reset2();
        getNmEquipment(tableId).then(response => {
            this.form2 = response.data;
        });
    }
    this.getList();
  },
  methods: {
    /** 查询设备维护信息列表 */
    getList() {
      this.loading = true;
      listNmEquipemntRecord(this.queryParams).then(response => {
        this.nmEquipemntRecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset2() {
      this.form2 = {
        id: null,
        equipmentWorkshop: null,
        equipmentImg: null,
        equipmentRenark: null,
        equipmentNo: null,
        productionDate: null,
        num: null,
        equipmentName: null,
        installationUnit: null,
        productionNo: null,
        model: null,
        overallDimension: null,
        totalWeight: null,
        liftingWeightMax: null,
        manufacturer: null,
        productionTime: null,
        medium: null,
        designFlow: null,
        speed: null,
        inletTemperature: null,
        normalFlow: null,
        shaftPower: null,
        viscosity: null,
        inletPressure: null,
        cavitationAllowance: null,
        lift: null,
        outletPressure: null,
        suctionTemperature: null,
        driving: null,
        drivingSpeed: null,
        explosionProofGrade: null,
        drivingMachine: null,
        drivingProductionDate: null,
        drivingManufacturer: null,
        equipmentOperationParameters: null,
        intermediateMaintenanceCycle: null,
        overhaulCycle: null,
        createTime: null
      };
      this.resetForm("form2");
    },
    // 表单重置
    reset() {
      this.form = {
        recodId: null,
        equipId: null,
        repairDate: null,
        repairPoepleName: null,
        repairPoepleId: null,
        faultPhenomenon: null,
        failureCauseAnalysis: null,
        maintenanceProcessRecord: null,
        createTime: null,
        createName: null,
        createId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.recodId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备维护信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const recodId = row.recodId || this.ids
      getNmEquipemntRecord(recodId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备维护信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.equipId  = this.equip_id;
          if (this.form.recodId != null) {
            updateNmEquipemntRecord(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addNmEquipemntRecord(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const recodIds = row.recodId || this.ids;
      this.$confirm('确认删除?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delNmEquipemntRecord(recodIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有设备维护信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportNmEquipemntRecord(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    /** 关闭按钮 */
    close() {
      // this.$store.dispatch("tagsView/delView", this.$route);
      // this.$router.push({ path: "/equipment/nmEquipment", query: { t: Date.now()}})

      const obj = { path: "/equipment/nmEquipment", query: { t: Date.now(), pageNum: this.$route.query.pageNum} };
      this.$tab.closeOpenPage(obj);

    },
    handleClick(tab, event) {
      this.activeName = tab.name;
    },
    /** 提交按钮 */
    submitEqForm() {
      this.$refs["form2"].validate(valid => {
        if (valid) {
          if (this.form2.eqpId != null) {
            updateNmEquipment(this.form2).then(response => {
              this.$modal.msgSuccess(response.msg);
              if (response.code === 200) {
                this.close();
              }
            });
          } else {
            addNmEquipment(this.form2).then(response => {
              this.$modal.msgSuccess(response.msg);
              if (response.code === 200) {
                this.close();
              }
            });
          }
        }
      });
    },
  }
};
</script>
